package data_structure.mooc;

import data_structure.helper.SwapArray;

public class SelectionSort {
    /**
     * select the sort of a given array
     * @param array
     * @param <E>
     * @return
     */
    public static <E extends Comparable<E>> E[] sort(E[] array){

        for(int i = 0; i < array.length; i++){
            int minIndex=i;
            for(int j = i+1; j < array.length; j++){
                if(array[minIndex].compareTo(array[j])>=0){
                    minIndex=j;
                }
            }
            SwapArray.swap (array,minIndex,i);
        }
        return array;
    }
}
